// ======
//                
//                 
//         
//                
//
// DeltaGlider.h
// Class interface for delta glider vessel class module
//
// Notes:
// * Two alternative sets of vessel capabilities are provided
//   ("easy" and "complex"), depending on user-selected option.
// * This interface covers both the "classic" (DeltaGlider) and
//   scramjet (DG-S) versions, distinguished by the SCRAMJET
//   entry in the definition file.
// ======

#ifndef __DELTAGLIDER_H
#define __DELTAGLIDER_H

//#define STRICT 1

#include "orbitersdk.h"
#include "Ramjet.h"
#include "resource.h"
#include "UMmuSDK.h"

// ======
// Some vessel class caps
// Where an entry consists of two values, the first refers to the
// "easy", the second to the "complex" flight model.
// ======

const double EMPTY_MASS    = 15000.0;  // standard configuration
const double EMPTY_MASS_SC = 27000.0;  // ramjet configuration
// DG mass w/o fuel

const double PSNGR_MASS    =     85.0;
// mass per passenger (including life support system)

const double TANK1_CAPACITY = 15400.0;
const double TANK2_CAPACITY =  2500.0;
// Main fuel tank capacities [kg] (can be split between rocket
// fuel and scramjet fuel)

const double RCS_FUEL_CAPACITY = 1000.0;
// Max fuel capacity: RCS tank [kg]



const double MAX_JET_THRUST[2] = {177928,177928};



const double MAX_MAIN_THRUST[2] = {3.0e5, 1.6e5};
// Main engine max vacuum thrust [N] per engine. (x2 for total)

const double MAX_RETRO_THRUST = 3.4e4;
// Retro engine max vacuum thrust [N] per engine. (x2 for total)

const double MAX_HOVER_THRUST[2] = {1.4e5, 1.1e5};
// Hover engine max vacuum thrust [N] (x2 for total)

const double MAX_RCS_THRUST = 1.7e3;
// Attitude control system max thrust [N] per engine.

const double ISP = 40000;//4e5;
// Vacuum Isp (fuel-specific impulse) for all thrusters [m/s]

const double ISPJET = 400000;//4e5;
// Vacuum Isp (fuel-specific impulse) for jet [m/s]


const double GEAR_OPERATING_SPEED = 0.1;
// Opening/closing speed of landing gear (1/sec)
// => gear cycle ~ 6.7 sec

const double AIR_LOCK_TUBE_OPERATING_SPEED = 0.05;


const double NOSE_OPERATING_SPEED = 0.05;
// Opening/closing speed of nose cone docking mechanism (1/sec)
// => cycle = 20 sec

const double AIRLOCK_OPERATING_SPEED = 0.1;
// Opening/closing speed of outer airlock (1/sec)
// => cycle = 10 sec

const double RADIATOR_OPERATING_SPEED = 0.03125;
// Deployment speed of radiator (1/sec)
// => cycle = 32 sec

const double REVERSER_OPERATING_SPEED = 0.3;

const double BAY_DOOR_OPERATING_SPEED = 0.1;

const double AIRBRAKE_OPERATING_SPEED = 0.3;
// Deployment speed of airbrakes
// => cycle = 3.3 sec

const double LADDER_OPERATING_SPEED = 0.1;
// Deployment speed of escape ladder

const double HATCH_OPERATING_SPEED = 0.15;
// Opening/closing speed of top hatch

const double RCOVER_OPERATING_SPEED = 0.3;
// Retro cover opening/closing speed

// == Main engine parameters =====

const double MAIN_PGIMBAL_RANGE = tan (1.0*RAD);
const double MAIN_YGIMBAL_RANGE = 1.0/7.7;
// main engine pitch and yaw gimbal range (tan)

const double MAIN_PGIMBAL_SPEED = 0.007;
const double MAIN_YGIMBAL_SPEED = 0.035;
// operating speed of main engine pitch and yaw gimbals

const double MAX_HOVER_IMBALANCE = 4e3;
// max thrust imbalance between front and aft hover engines [N]

const double HOVER_BALANCE_SPEED = 2e3;
// operating speed of hover balance shift control

// === Scramjet parameters 

const double SCRAM_FUEL_CAPACITY = 5000.0;
// Max. scramjet fuel capacity [kg]

const double SCRAM_TEMAX[2] = {3500.0, 3200.0};
// Max. scramjet exhaust temperature [K]

const double SCRAM_FHV[2] = {3.5e8, 2.0e8};
// Scramjet fuel heating value [J/kg]: Amount of heat energy
// obtained from burning 1kg of propellant

const double SCRAM_MAX_DMF[2] = {2.0,3.0};
// Max. scramjet fuel flow rate [kg/s]

const double SCRAM_INTAKE_AREA = 1.0;
// Scramjet intake cross section (per engine) [m^2]

const double SCRAM_DEFAULT_DIR = 9.0*RAD;
// Default scramjet thrust angle (rad)

const double SCRAM_GIMBAL_RANGE = 5.0*RAD;
// Scramjet gimbal range (rad)

const double SCRAM_GIMBAL_SPEED = SCRAM_GIMBAL_RANGE/3.0;
// Operating speed of scramjet pitch gimbals (rad/s)

// ===== Damage parameters 

const double WINGLOAD_MAX =  16e3;
const double WINGLOAD_MIN = -10e3;
// Max. allowed positive and negative wing load [N/m^2]

const double DYNP_MAX = 300e3;
// Max. allowed dynamic pressure [Pa]

// ===




const int nsurf = 12; // number of bitmap handles


const double MAX_GRAPPLING_DIST = 0.5f;
const double MAX_GRAPPLING_ANG  = 0.9f; //(cos(angle)>0.9f)

// ==========================================================
// Interface for derived vessel class: DeltaGlider
// ==========================================================

class DeltaGlider: public VESSEL2 {
public:
	DeltaGlider (OBJHANDLE hObj, int fmodel);
	~DeltaGlider ();
	void SetEmptyMass () const;
	void DefineAnimations ();
	
	void ReleaseSurfaces();
	void InitPanel (int panel);
	inline bool ScramVersion() const { return scramjet != NULL; }
	void DrawHUD (int mode, const HUDPAINTSPEC *hps, HDC hDC);
	void DrawNeedle (HDC hDC, int x, int w, double rad, double angle, double *pangle = 0, double speed = PI);
	void SetPassengerVisuals ();
	bool RedrawPanel_AOA (SURFHANDLE surf, bool force = false);
	bool RedrawPanel_Slip (SURFHANDLE surf, bool force = false);
	bool RedrawPanel_Wingload (SURFHANDLE surf, bool force = false);
	void RedrawPanel_Navmode (SURFHANDLE surf);
	bool RedrawPanel_Throttle (SURFHANDLE surf);
	bool RedrawPanel_ThHover (SURFHANDLE surf);
	bool RedrawPanel_ThScram (SURFHANDLE surf);
	bool RedrawPanel_ElevTrim (SURFHANDLE surf);
	bool RedrawPanel_RotVelocity (SURFHANDLE surf, int which);
	bool RedrawPanel_RotAcceleration (SURFHANDLE surf, int which);
	bool RedrawPanel_RotMoment (SURFHANDLE surf, int which);
	bool RedrawPanel_ScramTempDisp (SURFHANDLE surf);
	bool RedrawPanel_WBrake (SURFHANDLE surf, int which);
	void RedrawPanel_MFDButton (SURFHANDLE surf, int mfd, int side);
	bool RedrawPanel_MainFlow (SURFHANDLE surf);
	bool RedrawPanel_RetroFlow (SURFHANDLE surf);
	bool RedrawPanel_HoverFlow (SURFHANDLE surf);
	bool RedrawPanel_ScramFlow (SURFHANDLE surf);
	bool RedrawPanel_MainTSFC (SURFHANDLE surf);
	bool RedrawPanel_ScramTSFC (SURFHANDLE surf);
	bool RedrawPanel_MainPropMass (SURFHANDLE surf);
	bool RedrawPanel_battery_charge_001 (SURFHANDLE surf);
	bool RedrawPanel_JetPropMass (SURFHANDLE surf);
	bool RedrawPanel_RCSPropMass (SURFHANDLE surf);
	
	bool RedrawPanel_ScramPropMass (SURFHANDLE surf);
	bool RedrawPanel_PGimbalMainDisp (SURFHANDLE surf);
	bool RedrawPanel_YGimbalMainDisp (SURFHANDLE surf);
	bool RedrawPanel_GimbalScramDisp (SURFHANDLE surf);
	bool RedrawPanel_HoverBalanceDisp (SURFHANDLE surf);
	bool RedrawPanel_GearIndicator (SURFHANDLE surf);
	bool RedrawPanel_NoseconeIndicator (SURFHANDLE surf);
	

	bool DecAttMode ();
	bool IncAttMode ();
	bool DecADCMode ();
	bool IncADCMode ();
	void SetMainRetroLevel (int which, double lmain, double lretro);
	void SetScramLevel (int which, double level);
	bool IncMainPGimbal (int which, int mode);
	void AdjustMainPGimbal (int &mode);
	bool IncMainYGimbal (int which, int mode);
	void AdjustMainYGimbal (int &mode);
	bool IncScramGimbal (int which, int mode);
	void AdjustScramGimbal (int &mode);
	bool ShiftHoverBalance (int mode);
	void AdjustHoverBalance (int &mode);
	//void TestDamage ();
	void ApplyDamage ();
	void RepairDamage ();
    void DefineSound();


	// Overloaded callback functions
	void clbkSetClassCaps (FILEHANDLE cfg);
	void clbkLoadStateEx (FILEHANDLE scn, void *vs);
	void clbkSaveState (FILEHANDLE scn);
	void clbkPostCreation ();
	void clbkVisualCreated (VISHANDLE vis, int refcount);
	void clbkVisualDestroyed (VISHANDLE vis, int refcount);
	//void clbkPreStep (double simT, double simDT, double mjd);
	void clbkPostStep (double simt, double simdt, double mjd);
	bool clbkPlaybackEvent (double simt, double event_t, const char *event_type, const char *event);
	void clbkDrawHUD (int mode, const HUDPAINTSPEC *hps, HDC hDC);
	void clbkRCSMode (int mode);
	void clbkADCtrlMode (DWORD mode);
	void clbkHUDMode (int mode);
	void clbkMFDMode (int mfd, int mode);
	void clbkNavMode (int mode, bool active);
	int  clbkConsumeDirectKey (char *kstate);
	int  clbkConsumeBufferedKey (DWORD key, bool down, char *kstate);
	bool clbkLoadGenericCockpit ();
	bool clbkLoadPanel (int id);
	bool clbkPanelMouseEvent (int id, int event, int mx, int my);
	bool clbkPanelRedrawEvent (int id, int event, SURFHANDLE surf);
	
	//char *line;
	double alt;       // altitude
	double range;     // glide range
	double aoa_ind;   // angle of AOA needle (NOT AOA!)
	double slip_ind;  // angle of slip indicator needle
	double load_ind;  // angle of load indicator needle
	int mpgimbalidx[2], mpswitch[2], mpmode; // main pitch gimbal slider positions and button states
	int mygimbalidx[2], myswitch[2], mymode; // main yaw gimbal slider positions and button states
	int scgimbalidx[2], sgswitch[2], spmode; // scramjet gimbal slider positions and button states
	int hbalanceidx, hbswitch, hbmode;       // hover balance slider position
	bool psngr[4];                           // passengers?
	bool bDamageEnabled;                     // damage/failure testing?
    //int ReturnCode;
	// parameters for failure modelling
	double lwingstatus, rwingstatus;
	int hatchfail;
	bool aileronfail[4];

	enum DoorStatus { DOOR_CLOSED, DOOR_OPEN, DOOR_CLOSING, DOOR_OPENING }
		TEST_STATUS, NOSE_CONE_STATUS, ladder_status, gear_status, rcover_status,  hatch_status, radiator_status, brake_status, 
			charging_status, test_status, engine_status, REVERSER_STSTUS, 
			BAY_DOOR_FORWARD_RIGHT_STATUS, BAY_DOOR_AFT_RIGHT_STATUS ,BAY_DOOR_FORWARD_LEFT_STATUS, BAY_DOOR_AFT_LEFT_STATUS,
			//airlock
			OUTER_AIRLOCK_DOOR_STATUS, INNER_AIRLOCK_DOOR_STATUS, AIRLOCK_TUBE_STATUS, CHAMBER_STATUS
			; 
		
		
	enum SystemStatus {SYSTEM_OFF, SYSTEM_ON} POWER, TURBINE_FUEL_LEFT_POWER, TURBINE_IGNITION_LEFT_POWER,TURBINE_START_LEFT_POWER, 
			TURBINE_FUEL_RIGHT_POWER, TURBINE_IGNITION_RIGHT_POWER,TURBINE_START_RIGHT_POWER,TURBINE_RUNNING_LEFT, TURBINE_RUNNING_RIGHT, TURBINE_STARTING_LEFT, TURBINE_STARTING_RIGHT, TURBINE_REVERSER, PARKING_BRAKE,
			SCRAM_FUEL_LEFT_POWER, SCRAM_IGNITION_LEFT_POWER, SCRAM_START_LEFT_POWER ,SCRAM_FUEL_RIGHT_POWER, SCRAM_IGNITION_RIGHT_POWER, SCRAM_START_RIGHT_POWER,
			ROCKET_FUEL_LEFT_POWER, ROCKET_IGNITION_LEFT_POWER, ROCKET_FUEL_RIGHT_POWER, ROCKET_IGNITION_RIGHT_POWER, BEACON_LIGHT_POWER, NAVIGATION_LIGHTS_POWER, 
			STROBE_LIGHTS_POWER, MASTER_BAY_DOORS_POWER, BAY_DOOR_FORWARD_RIGHT_POWER, BAY_DOOR_AFT_RIGHT_POWER, BAY_DOOR_FORWARD_LEFT_POWER, BAY_DOOR_AFT_LEFT_POWER, 
			//airlock
            OUTER_AIR_LOCK_DOOR_POWER, INNER_AIR_LOCK_DOOR_POWER, AIRLOCK_TUBE_POWER, AIRLOCK_MASTER_POWER, NOSE_CONE_POWER, CHAMBER_POWER, DOCK_RELEASE_POWER,
			// Environmental Life Support System
			FAN_AIR_LOOP_001, FAN_AIR_LOOP_002, FAN_AIR_LOOP_003
			;
	
    //airlock systems
    void ExtendAirLock (DoorStatus action);
	void ActivateNoseCone (DoorStatus action);
    void ActivateOuterAirlock (DoorStatus action);
	void ActivateInnerAirlock (DoorStatus action);

	void ActivateLandingGear (DoorStatus action);
	void ActivateLadder (DoorStatus action);
	void ActivateHatch (DoorStatus action);
	void ActivateAirbrake (DoorStatus action);
	void ActivateRadiator (DoorStatus action);
	void ActivateReverser (DoorStatus action);
	void Activate_bay_door_forward_right (DoorStatus action); 
	void Activate_bay_door_forward_left (DoorStatus action); 
	void Activate_bay_door_aft_right (DoorStatus action);
	void Activate_bay_door_aft_left (DoorStatus action);
	void CHANGE_ENGINE_MODE (DoorStatus action);
	
	void RCS_MODE ();
	void RevertReverser ();
	void RevertLandingGear ();
	void RevertLadder ();
	void RevertOuterAirlock ();
	void RevertInnerAirlock ();
	void RevertHatch ();
	void RevertAirbrake ();
	void RevertRadiator ();
	void SetGearParameters (double state);
	
	void LifeSupportSystem();
    


     
	double TURBINE_STARTING_LEFT_TIMER;
	double TURBINE_STARTING_RIGHT_TIMER;
	double leftstartjet;
    double rightstartjet;
    
	//Environmental Life Support System
	bool Redraw_Environmental_Control (SURFHANDLE surf); 
	
    int totalcrew;

    int RedrawTimer;
	double PanelRedrawTimer;
	double Cabin_Temp_Timing;
    double Cabin_Temp_Timing_check;
	double lastSimTime;
	int Update_Temp;
    double CabinTemp;
	double CabinThermostatSet;
	double CabinTemperatureSet;
	double RadiatorTemp1;
    double RadiatorTemp2;
	double RadiatorTemp3;
    double RadiatorTemp4;
	int Radiator_loop;
	
	int CabinThermostat;
    int carbon_dioxide_code;
	int RadiatorThermostat1;
    int RadiatorThermostat2;
    int RadiatorThermostat3;
    int RadiatorThermostat4;
	
	int ShipAge_seconds;
    int ShipAge_Min;
	int ShipAge_hours;
    double carbon_dioxide_level_001;
    double carbon_dioxide_level_002;
    int Environmental_Control_Computer_page;
    int Environmental_Control_Computer_page_Count;






	double  ladder_proc, gear_proc, rcover_proc, hatch_proc, radiator_proc, brake_proc, charging_proc, engine_proc, reverser_proc,
	bay_door_forward_right_proc, bay_door_forward_left_proc, bay_door_aft_right_proc, bay_door_aft_left_proc,
	//airlock
    nose_cone_proc,  outer_air_lock_proc, inner_air_lock_proc, air_lock_tube_proc

	;    



    UINT anim_air_lock_tube;
	UINT anim_gear;         // handle for landing gear animation
	UINT anim_rcover;       // handle for retro cover animation
	UINT anim_nose;         // handle for nose cone animation
	UINT anim_ladder;       // handle for front escape ladder animation
	UINT anim_olock;        // handle for outer airlock animation
	UINT anim_ilock;        // handle for inner airlock animation
	UINT anim_hatch;        // handle for top hatch animation
	UINT anim_radiator;     // handle for radiator animation
	UINT anim_rudder;       // handle for rudder animation
	UINT anim_elevator;     // handle for elevator animation
	UINT anim_elevatortrim; // handle for elevator trim animation
	UINT anim_laileron;     // handle for left aileron animation
	UINT anim_raileron;     // handle for right aileron animation
	UINT anim_brake;        // handle for airbrake animation
	UINT anim_reverser;
	UINT anim_bay_door_forward_right;
	UINT anim_bay_door_forward_left;
	UINT anim_bay_door_aft_right;
	UINT anim_bay_door_aft_left;
	/*
	UINT anim_mainthrottle[2];  // VC main/retro throttle levers (left and right)
	UINT anim_hoverthrottle;    // VC hover throttle
	UINT anim_scramthrottle[2]; // VC scram throttle levers (left and right)
	UINT anim_gearlever;        // VC gear lever
	UINT anim_nconelever;       // VC nose cone lever
	UINT anim_pmaingimbal[2];   // VC main engine pitch gimbal switch (left and right engine)
	UINT anim_ymaingimbal[2];   // VC main engine yaw gimbal switch (left and right engine)
	UINT anim_scramgimbal[2];   // VC scram engine pitch gimbal switch (left and right engine)
	UINT anim_hbalance;         // VC hover balance switch
	UINT anim_hudintens;        // VC HUD intensity switch
	UINT anim_rcsdial;          // VC RCS dial animation
	UINT anim_afdial;           // VC AF dial animation
	UINT anim_olockswitch;      // VC outer airlock switch animation
	UINT anim_ilockswitch;      // VC inner airlock switch animation
	UINT anim_retroswitch;      // VC retro cover switch animation
	UINT anim_ladderswitch;     // VC ladder switch animation
	UINT anim_hatchswitch;      // VC hatch switch animation
	UINT anim_radiatorswitch;   // VC radiator switch animation
*/
	SURFHANDLE srf[nsurf];          // handles for panel bitmaps
	SURFHANDLE insignia_tex;        // vessel-specific fuselage markings
	MESHHANDLE exmesh, exmesh_tpl;  // local external mesh and global template
	MESHHANDLE vcmesh, vcmesh_tpl;  // local VC mesh and global template
	THGROUP_HANDLE thg_main;
	THGROUP_HANDLE thg_retro;
	THGROUP_HANDLE thg_hover;

	enum {CAM_GENERIC, CAM_PANELMAIN, CAM_PANELUP, CAM_PANELDN, CAM_EVA} campos;

	BEACONLIGHTSPEC beacon[7];                   // light beacon definitions
	void SetNavlight (bool on);
	void SetBeacon (bool on);
	void SetStrobe (bool on);
	
	double GetThrusterFlowRate(THRUSTER_HANDLE th);  // D. Beachy: get thruster flow rate in kg/s
	int MyID;

	
	
//-------------child group object pointers start ------------------------------------
//-------- gear child pointers start ----------
      MGROUP_TRANSLATE *m_nose_oleo_piston;
	  MGROUP_TRANSLATE *m_nose_axle;
      MGROUP_TRANSLATE *m_nose_axle_cylinder;
      MGROUP_TRANSLATE *m_nose_axle_piston;
      MGROUP_ROTATE *m_nose_gear_wheels;
    // right rear gear doors  
	  MGROUP_ROTATE *m_gear_door_rear_02_right;	
      MGROUP_ROTATE *m_gear_door_rear_02_left;	
      MGROUP_TRANSLATE *m_oleo_piston_right_side;
      MGROUP_ROTATE *m_axle_right_side;
      MGROUP_ROTATE *m_axle_piston_right;
      MGROUP_ROTATE *m_wheel_right_rear_right_side;	
      MGROUP_ROTATE *m_wheel_right_front_right_side;
      MGROUP_ROTATE *m_wheel_left_rear_right_side;	
      MGROUP_ROTATE *m_wheel_left_front_right_side;


      MGROUP_TRANSLATE *m_oleo_piston_left_side;
      MGROUP_ROTATE *m_axle_left_side;
      MGROUP_ROTATE *m_axle_piston_left;
      MGROUP_ROTATE *m_wheel_right_rear_left_side;	
      MGROUP_ROTATE *m_wheel_right_front_left_side;
      MGROUP_ROTATE *m_wheel_left_rear_left_side;	
      MGROUP_ROTATE *m_wheel_left_front_left_side;
      
	  //nose cone
	  MGROUP_TRANSLATE *m_nose_cone_pin;
	  
	  //air lock
	  MGROUP_TRANSLATE *m_inside_tube;
      MGROUP_TRANSLATE *m_outside_tube_002;
      MGROUP_TRANSLATE *m_outter_air_lock;
      
	  // air lock outer door
      MGROUP_ROTATE *m_outer_air_lock_pedal_001_part_001;
      MGROUP_ROTATE *m_outer_air_lock_pedal_001_part_002;
      MGROUP_ROTATE *m_outer_air_lock_pedal_001_part_003;
      MGROUP_ROTATE *m_outer_air_lock_pedal_002_part_001;
      MGROUP_ROTATE *m_outer_air_lock_pedal_003_part_001;
      MGROUP_ROTATE *m_outer_air_lock_pedal_004_part_001;
      MGROUP_ROTATE *m_outer_air_lock_pedal_005_part_001;
      MGROUP_ROTATE *m_outer_air_lock_pedal_006_part_001;
      MGROUP_ROTATE *m_outer_air_lock_pedal_007_part_001;
	  MGROUP_ROTATE *m_outer_air_lock_pedal_008_part_001;
      MGROUP_ROTATE *m_outer_air_lock_pedal_009_part_001;
      MGROUP_ROTATE *m_outer_air_lock_pedal_010_part_001;

      // air lock inner door
      MGROUP_ROTATE *m_inner_air_lock_pedal_001_part_001;
      MGROUP_ROTATE *m_inner_air_lock_pedal_001_part_002;
      MGROUP_ROTATE *m_inner_air_lock_pedal_001_part_003;
      MGROUP_ROTATE *m_inner_air_lock_pedal_002_part_001;
      MGROUP_ROTATE *m_inner_air_lock_pedal_003_part_001;
      MGROUP_ROTATE *m_inner_air_lock_pedal_004_part_001;
      MGROUP_ROTATE *m_inner_air_lock_pedal_005_part_001;
      MGROUP_ROTATE *m_inner_air_lock_pedal_006_part_001;
      MGROUP_ROTATE *m_inner_air_lock_pedal_007_part_001;
	  MGROUP_ROTATE *m_inner_air_lock_pedal_008_part_001;
      MGROUP_ROTATE *m_inner_air_lock_pedal_009_part_001;
      MGROUP_ROTATE *m_inner_air_lock_pedal_010_part_001;










//====
//             BJ's vars & functions
//====

 THRUSTER_HANDLE main_temp;

       OBJHANDLE OHplanet;
       VECTOR3 pos, SunToPlanet_vector, sunPos, pos2, PlanetToVessel_vector;
       double Vessalt;
       OBJHANDLE hVessel;
       long double distancePlanetToSun;
       ATMPARAM prm;
       double rad;
       long double distancePlanetToVessel;
       bool is_behind;
       double DistPtoL;
       double y;
       int check;
       int type; //1 is turbo 0 is rocket
       bool first_frame;
       bool warmed_up;
       bool warmed_up1;
       double eng_settings;
       double eng_settings1;
       bool winding_down;
       bool winding_down1;
       bool APU_on;
       bool Jetengine_on;
       bool Jetengine_on1;
       bool can_power;bool can_power1;bool can_power2;bool can_power3;bool can_power4;
       bool engine_turn_off;
       bool engine_turn_off1;
       int HUD_PANEL_ID;
       int HUD_PANEL_STATE;
       int CHECK_HUD_PANEL_STATE;
       void behindPlanet(void);
       double get_angle_between_in_radians(long double ax, long double ay, long double az, long double bx, long double by, long double bz);
       void revertEngine (int status);
	   void revertEngine2 (int status);
       void DeleteExhaust (void);
       void setScram (void);
       
       void jet(int status);
       int getEngineMode(void);
       double setMaxThrust(void);
       double ReturnJetThrust(void);
       void handleJet(bool x);
       bool APU_go(void);
       void engine_goSET(bool x, bool which);
       void APU_goSET(bool x);

	   void EngineHandle(void);
 


       //overloaded operators
       bool engine_go(DoorStatus *x, bool which);
       bool engine_go(bool x);



       PSTREAM_HANDLE main_exhaust1;
       PSTREAM_HANDLE main_exhaust2;
       DOCKHANDLE MainDockHandle;

	   
       double battery_charge_001;          //this is how much power the batteries have
       double battery_charge_002; 
	   double battery_charge_003; 
	   double battery_charge_004; 
	   int CabinThermostat_battery_loop;
	 
	   double battery_charge_Rate_001; 
	   double battery_charge_Rate_002; //this is how much the batteries get charged
	   double battery_charge_Rate_003;
	   double battery_charge_Rate_004;
       
	   double battery_draw_001;            //This is how much draw is being put on batteries
	   double battery_draw_002;
	   double battery_draw_003;
	   double battery_draw_004;
       bool batteryIsCharging;
       bool can_charge[3];
       
       
       #define solar_panel1 1
       #define solar_panel2 2
       #define solar_panel3 3
       #define solar_panel4 4


//declarations
void Battery_handle(void);
bool BatteryIsCharging(void);
void set_vars(double charge = 100);
void set_solarCharge(bool can);
double rand(void);
void set_damage(double numb, int which);

bool damaged_parts[5]; //damaged_parts[0] not used
bool damage_partsRND[5]; //damage_partsRND[0] not used

//lower panel
void ActivateAPI (DoorStatus action);//no idea
void ActivateAPU (DoorStatus action);
bool engine_activateJET(bool x, bool which);


//===============================================
//           --END OF-- BJ's vars & functions
//==================================================

//===============================================
// Define sound callouts
//===============================================
#define GEARDOWN				1     //  PlayVesselWave3(MyID,GEARDOWN,LOOP,225,0); <- this will play this sound
#define gear_retracted          2
#define jet_starting            3


//============================
// UMMU 1.5 DECLARATION
//============================
    void clbkFocusChanged(bool getfocus,OBJHANDLE hNewVessel,OBJHANDLE hOldVessel);
    UMMUCREWMANAGMENT Crew;
	void clbkSetClassCaps_UMMu(void);	// our special SetClassCapfunction added for more readability
	int SelectedUmmuMember;				// for the SDK demo, select the member to eva
	int UmmuSdKInitReturnCode;			// to display init message to user (in case Ummu isn't installed on Orbiter)

	// our custom oapiDebugString() function (an orbiter function that display debug text at bottom of screen)
	// Our custom function display only message if we have focus. The variables below is used by this function.
	// don't forget if you use such text interface in your vessel that you must initialise the variables
	// in set class cap and do also some code in clbkFocusChanged
	char cOurMessage[1000];
	char *SendFocusScreenMessage();	

	// If you want to use standard ID function see bottom of UMmuExample.cpp
	int EvaCrewMemberWithStandardSpacesuit(char* CrewName);

    
	
	bool DeltaGlider::Redraw_Crew_Member_Name (SURFHANDLE surf);
char cbuf[20];
//char *CrewName;
 
bool Redraw_Crew_Total_Number (SURFHANDLE surf);
bool DeltaGlider::Redraw_Enter_Airlock (SURFHANDLE surf);   
bool Redraw_Cargo_Name (SURFHANDLE surf);
void Grapple_Cargo();


int cargoUpDown;
int totalcargo;
double CARGO_MAX_DIST; // meters
VECTOR3 Cargo_Position;



char Name[20];
int SelectedCrgo;
int ReturnCode;

private:
	bool RedrawPanel_IndicatorPair (SURFHANDLE surf, int *p, int range);
	bool RedrawPanel_Number (SURFHANDLE surf, int x, int y, char *num);
	bool RedrawPanel_Number_1 (SURFHANDLE surf, int x, int y, char *num);
	
	Ramjet *scramjet;                            // scramjet module (NULL = none)
	void ScramjetThrust ();                      // scramjet thrust calculation

	bool bMWSActive, bMWSOn;                     // master warning flags
	int modelidx;                                // flight model index
	int tankconfig;                              // 0=rocket fuel only, 1=scramjet fuel only, 2=both
	double max_rocketfuel, max_scramfuel,max_jetfule, max_battery;        // max capacity for rocket and scramjet fuel
	VISHANDLE visual;                            // handle to DG visual representation
	SURFHANDLE skin[3];                          // custom skin textures, if applicable
	char skinpath[32];                           // skin directory, if applicable
	PROPELLANT_HANDLE ph_main, ph_rcs, ph_scram,ph_jet; // propellant resource handles
	//THRUSTER_HANDLE th_main[2];                  // main engine handles
	//THRUSTER_HANDLE th_retro[2];                 // retro engine handles
	//THRUSTER_HANDLE th_hover[2];                 // hover engine handles
	//THRUSTER_HANDLE th_main[2];                 // scramjet handles
	
	ATTACHMENTHANDLE  payload_attachment[6];
	
	THRUSTER_HANDLE th_main[2];                  // main engine handles
	THRUSTER_HANDLE th_main2[2]; 
	THRUSTER_HANDLE th_retro[2];                 // retro engine handles
	THRUSTER_HANDLE th_oms[2];
	THRUSTER_HANDLE th_hover[2];                 // hover engine handles
	//THRUSTER_HANDLE th_main[2];                 // scramjet handles
	THRUSTER_HANDLE th_att_rot_up[2];
	THRUSTER_HANDLE th_att_rot_down[2];
	THRUSTER_HANDLE th_att_lin_up[2];
	THRUSTER_HANDLE th_att_lin_down[2];
	THRUSTER_HANDLE th_att_rot_yaw_left[4];
	THRUSTER_HANDLE th_att_rot_yaw_right[4];
	THRUSTER_HANDLE th_att_lin_left[4];
	THRUSTER_HANDLE th_att_lin_right[4];
	THRUSTER_HANDLE th_att_rot_bank_left[2];
	THRUSTER_HANDLE th_att_rot_bank_right[2];
	THRUSTER_HANDLE th_att_lin_forward[4];
	THRUSTER_HANDLE th_att_lin_backward[4];
	
	
	
	AIRFOILHANDLE hwing;                         // airfoil handle for wings
	CTRLSURFHANDLE hlaileron, hraileron;         // control surface handles
	PSTREAM_HANDLE hatch_vent;
	double hatch_vent_t;
	bool dockreleasedown;

	UINT engsliderpos[5];    // throttle settings for main,hover,scram engines
	UINT elevtrimpos;        // elevator trim indicator position
	double scram_intensity[2];
	double scram_max[2];
	UINT wbrake_pos[2];
	int mainflowidx[2], retroflowidx[2], hoverflowidx, scflowidx[2];
	int mainTSFCidx, scTSFCidx[2];
	int mainpropidx[2], rcspropidx[2], scrampropidx[2];
	double mainpropmass, rcspropmass, scrampropmass, jetpropmass, batpropmass;
	int rotidx[3][3];

	struct PrpDisp {        // propellant status display parameters
		int dsp_main,      dsp_rcs;
		char lvl_main[8],  lvl_rcs[8];
		char mass_main[8], mass_rcs[8];
		char flow_main[8], flow_rcs[8];
	} p_prpdisp;

	struct EngDisp {       // engine status display parameters
		int  bar[2];
		char dsp[6][8];
	} p_engdisp;

	struct RngDisp {
		char dsp[2][10];
	} p_rngdisp;
};

typedef struct {
	HINSTANCE hDLL;
	HFONT font[4];
	HFONT hFont[1];
	DWORD col[4];
	HBRUSH brush[4];
	HPEN pen[2];
} GDIParams;




// Some mesh groups referenced in the code
#define MESHGRP_VC_HUDMODE          0
#define MESHGRP_VC_HBALANCECNT     18
#define MESHGRP_VC_SCRAMGIMBALCNT  19
#define MESHGRP_VC_PGIMBALCNT      20
#define MESHGRP_VC_YGIMBALCNT      21
#define MESHGRP_VC_NAVMODE         59
#define MESHGRP_VC_LMFDDISP       109
#define MESHGRP_VC_RMFDDISP       110
#define MESHGRP_VC_STATUSIND      118
#define MESHGRP_VC_HORIZON        120
#define MESHGRP_VC_HUDDISP        136

// Panel area identifiers:
// Panel 0
#define AID_PROPELLANTSTATUS     0
#define AID_ENGINEMAIN           2
#define AID_ENGINEHOVER          3
#define AID_ENGINESCRAM          4
#define AID_ATTITUDEMODE         5
#define AID_ADCTRLMODE           6
#define AID_NAVMODE              7
#define AID_HUDMODE              8
#define AID_AOAINSTR             9
#define AID_SLIPINSTR           10
#define AID_LOADINSTR           11
#define AID_HORIZON             13
#define AID_MFD1_BBUTTONS       14
#define AID_MFD1_LBUTTONS       15
#define AID_MFD1_RBUTTONS       16
#define AID_MFD2_BBUTTONS       17
#define AID_MFD2_LBUTTONS       18
#define AID_MFD2_RBUTTONS       19
#define AID_PGIMBALMAIN         22
#define AID_PGIMBALMAINMODE     23
#define AID_YGIMBALMAIN         24
#define AID_YGIMBALMAINMODE     25
#define AID_GIMBALSCRAM         26
#define AID_GIMBALSCRAMMODE     27
#define AID_ELEVATORTRIM        28
#define AID_PGIMBALMAINDISP     29
#define AID_YGIMBALMAINDISP     30
#define AID_GIMBALSCRAMDISP     31
#define AID_MAINDISP1           32
#define AID_MAINDISP2           33
#define AID_MAINDISP3           34
#define AID_MAINDISP4           35
#define AID_SCRAMDISP2          36
#define AID_SCRAMDISP3          37
#define AID_MAINPROP            38
#define AID_MAINPROPMASS        39
#define AID_RCSPROP             40
#define AID_RCSPROPMASS         41
#define AID_SCRAMPROP           42
#define AID_SCRAMPROPMASS       43
#define AID_HOVERBALANCE        44
#define AID_HBALANCEMODE        45
#define AID_HBALANCEDISP        46
#define AID_RADIATORSWITCH      47
#define AID_RETRODOORSWITCH     48
#define AID_HATCHSWITCH         49
#define AID_LADDERSWITCH        50
#define AID_MWS                 51
#define AID_CHARGING            52
#define AID_JETPROPMASS         53
#define AID_Cargo_Name          54
#define AID_Cargo_Selector     55
#define AID_HUD_PANEL_ID0       57 // a way to track panel ID
#define AID_HUD_PANEL_ID1       58 // a way to track panel ID
#define AID_HUD_PANEL_ID2       59 // a way to track panel ID
#define AID_HUD_PANEL_ID3       60 // a way to track panel ID
#define AID_HUD_PANEL_ID4       61 // a way to track panel ID
// Panel 1 bitmap panel1
#define AID_BATTERYCHARGE       62

//Environmental Life Support System
#define AID_Environmental_Control 63
#define AID_CabinTemperature     64
#define AID_CabinTemperatureSet  65

#define AID_NAVIGATION_SWITCH         102
#define AID_BEACON_SWITCH           103
#define AID_STROBE_SWITCH           104
#define AID_VPITCH                 105
#define AID_VBANK                  106
#define AID_VYAW                   107
#define AID_APITCH                 108
#define AID_ABANK                  109
#define AID_AYAW                   110
#define AID_MPITCH                 111
#define AID_MBANK                  112
#define AID_MYAW                   113
#define AID_SCRAMTEMPDISP          114
//turbine left
#define AID_TURBINE_FUEL_LEFT      115
#define AID_TURBINE_IGNITION_LEFT  116
#define AID_TURBINE_START_LEFT     117
// turbine right 
#define AID_TURBINE_FUEL_RIGHT      118
#define AID_TURBINE_IGNITION_RIGHT  119
#define AID_TURBINE_START_RIGHT     120
#define AID_TURBINE_REVERSER        121
#define AID_GEARSWITCH              122

// brake
#define AID_PARKING_BRAKE           123
//scram system
#define AID_SCRAM_FUEL_LEFT         124
#define AID_SCRAM_IGNITION_LEFT     125
#define AID_SCRAM_START_LEFT        126

#define AID_SCRAM_FUEL_RIGHT        127
#define AID_SCRAM_IGNITION_RIGHT    128
#define AID_SCRAM_START_RIGHT       129

//rocket system
#define AID_ROCKET_FUEL_LEFT         130
#define AID_ROCKET_IGNITION_LEFT     131


#define AID_ROCKET_FUEL_RIGHT        132
#define AID_ROCKET_IGNITION_RIGHT    133

#define AID_EXTEND_AIRLOCK           134
#define AID_CHAMBER                  135
#define AID_INNER_AIRLOCK_DOOR       136
#define AID_OUTER_AIRLOCK_DOOR       137
#define AID_DOCK_RELEASE             138

#define AID_BAY_DOOR_FORWARD_RIGHT   139
#define AID_BAY_DOOR_AFT_RIGHT       140
#define AID_BAY_DOOR_FORWARD_LEFT    141
#define AID_BAY_DOOR_AFT_LEFT        142



// Panel 2
#define AID_WBRAKE_BOTH        200
#define AID_WBRAKE_LEFT        201
#define AID_WBRAKE_RIGHT       202

#define AID_NOSECONE           204
#define AID_GEARINDICATOR      205
#define AID_NOSECONEINDICATOR  206
#define AID_DOCKRELEASE        207
#define AID_ENGINE_MODE        208
// Eva Display
#define AID_Crew_Member_Name   400
#define AID_Crew_Total_Number  401
#define AID_EVA_Selector       402
#define AID_Cargo_Load         403
#define AID_Enter_Airlock      404

// over head power panel
#define AID_MASTER_POWER                    500
//Bay doors
#define AID_MASTER_BAY_DOORS_POWER          501
#define AID_BAY_DOOR_FORWARD_RIGHT_POWER    502
#define AID_BAY_DOOR_AFT_RIGHT_POWER        503
#define AID_BAY_DOOR_FORWARD_LEFT_POWER     504
#define AID_BAY_DOOR_AFT_LEFT_POWER         505
// air lock system
#define AID_NOSECONE_POWER                  506
#define AID_EXTEND_AIRLOCK_POWER            507
#define AID_CHAMBER_POWER                   508
#define AID_INNER_AIRLOCK_DOOR_POWER        509
#define AID_OUTER_AIRLOCK_DOOR_POWER        510
#define AID_DOCK_RELEASE_POWER              511
#define AID_AIR_LOCK_SYSTEM_POWER           512



#define AID_APISWITCH          99901
/*
// Virtual cockpit-specific area identifiers:
#define AID_MFD1_PWR          1024
#define AID_MFD1_SEL          1025
#define AID_MFD1_MNU          1026
#define AID_MFD2_PWR          1027
#define AID_MFD2_SEL          1028
#define AID_MFD2_MNU          1029
#define AID_HUDBUTTON1        1030
#define AID_HUDBUTTON2        1031
#define AID_HUDBUTTON3        1032
#define AID_HUDBUTTON4        1033
#define AID_HUDCOLOUR         1034
#define AID_HUDINCINTENS      1035
#define AID_HUDDECINTENS      1036
#define AID_NAVBUTTON1        1037
#define AID_NAVBUTTON2        1038
#define AID_NAVBUTTON3        1039
#define AID_NAVBUTTON4        1040
#define AID_NAVBUTTON5        1041
#define AID_NAVBUTTON6        1042
#define AID_RADIATOREX        1043
#define AID_RADIATORIN        1044
#define AID_HATCHOPEN         1045
#define AID_HATCHCLOSE        1046
#define AID_LADDEREX          1047
#define AID_LADDERIN          1048
#define AID_RCOVEROPEN        1049
#define AID_RCOVERCLOSE       1050
#define AID_ILOCKOPEN         1051
#define AID_ILOCKCLOSE        1052
#define AID_OLOCKOPEN         1053
#define AID_OLOCKCLOSE        1054
#define AID_NCONEOPEN         1055
#define AID_NCONECLOSE        1056
#define AID_GEARDOWN          1057
#define AID_GEARUP            1058
*/



#endif // !__DELTAGLIDER_H

